const Controllers = require('../controllers/Controller.js').controller;
const app = getApp();
Page({
  data: {
    globalStype:'',
  	shopGoodsPagedata:[],
    pageNumber:1,
    pageSize:10,
    isEnd:false,
    type:0,
    isloading:true,
    inputValue:'',
    shopId:'',
    iscancel:false,
    name:'',
    vip:''
  },

  onLoad(option) {
    this.setData({globalStype:app.globalData.globalStype})
  	if(app.globalData.shopId){
	  	this.setData({
	  		shopId:app.globalData.shopId
	  	})
  	}
    if(option.name){
      this.setData({
        name:option.name
      })
    }
    this.setData({
      vip:app.globalData.myshopinfo.vip
    })
  },
  bindInput(e){
      var value=e.detail.value || ''
      if(value){
        this.setData({
          inputValue: value
        })
      }
  },
  searchSubmit(e){
      var _SearchValue=this.data.inputValue;
      let localStorageValue = [];
      if (_SearchValue && _SearchValue!=null) {
      	this.setData({
	      shopGoodsPagedata:[],
	      pageNumber:1,
	      pageSize:10,
	      isEnd:false,
	      isloading:true
	    })
      	this.shopGoodsPage()
      }else{
        wx.showToast({
            title: '请输入您要搜索的内容',
            icon:'none'
          })
      }
  },
  clear(){
  	this.setData({
      inputValue:'',
      iscancel:false
    })
  },
  shopGoodsPage(){
    Controllers.shopGoodsPage({
      pageSize:this.data.pageSize,
      pageNumber:this.data.pageNumber,
      goodsName:this.data.inputValue,
      shopId:this.data.shopId
    }).then(res => {
      if(res.data.list.length>0){
        for(let item of res.data.list){
          if(item.label)
          item.label=item.label.split('/')
        }
        this.setData({
          shopGoodsPagedata:this.data.shopGoodsPagedata.concat(res.data.list),

        })
        
      }
      if(res.data.lastPage){
          this.setData({
            isEnd:true
          })
        }
      this.setData({
      	isloading:false,
      	iscancel:true
      })
    });
  },
  onReachBottom() {
    if (this.data.isEnd) {
      return;
    } else {
      this.setData({
          pageNumber: this.data.pageNumber + 1,
      });
      this.shopGoodsPage()
    }
  },
})